import 'package:flutter/material.dart';
import 'package:flutter_get_x/resource_config.dart';
import 'package:get/get.dart';

import 'logic.dart';
import 'state.dart';

class LoginPage extends StatelessWidget {
  final LoginLogic logic = Get.put(LoginLogic());
  final LoginState state = Get.find<LoginLogic>().state;

  _buildTextField(BuildContext context, String image, String label, String hint, TextEditingController controller) {
    return Container(
      margin: EdgeInsets.only(left: 20, top: 10, right: 20),
      decoration: BoxDecoration(border: Border(bottom: BorderSide(color: Colors.black12))),
      child: Row(
        children: [
          Expanded(
            flex: 0,
            child: Container(
              margin: EdgeInsets.only(right: 5),
              child: Image.asset(image),
            ),
          ),
          Expanded(
            flex: 0,
            child: Container(
              child: Text(label),
              width: 50,
            ),
          ),
          Expanded(
            flex: 1,
            child: Padding(
              padding: EdgeInsets.all(0),
              child: TextField(
                controller: controller,
                decoration:
                    InputDecoration(hintText: hint, border: InputBorder.none),
              ),
            ),
          ),
        ],
      ),
    );
  }

  _buildInputLayout(BuildContext context) {
    return Container(
      child: Column(
        children: [
          _buildTextField(context, ResourceConfig.IMG_ICON_ACCOUNT, "登录名", "请输入用户名/手机", logic.uNController),
          _buildTextField(context, ResourceConfig.IMG_ICON_PWD, "密码", "请输入密码", logic.pwdController),
        ],
      ),
    );
  }

  _buildLoginLayout(BuildContext context) {
    return Container();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          child: Column(
            children: [
              Image.asset(
                ResourceConfig.IMG_TOP_BG,
                fit: BoxFit.cover,
                width: double.infinity,
              ),
              _buildInputLayout(context),
              // _buildLoginLayout(context),
            ],
          ),
        ),
      ),
    );
  }
}
